//
// Created by Administrator on 2021/10/21.
//

#ifndef MRENDER_OBJECT3D_H
#define MRENDER_OBJECT3D_H

#include "Object.h"
#include "MAssert.h"
#include "../math/Vector3.h"
#include "IRenderable.h"
#include "IDrawUIable.h"
#include "BufferGeometry.h"
#include "../matrials/Material.h"

/**
 * 3D对象基类， 场景、相机和Mesh基于此类
 */
class Object3D : public Object, public IRenderable, public IDrawUIable {
private:
    Matrix4x4 toApplyMatrix;
    Matrix4x4 getRotationMatrix();
public:
    /**
     * 材质
     */
    Material *p_material;
    /**
     * 几何体列表
     */
    std::vector<BufferGeometry*> geometries;
public:
    String type;
    /**
     * 增长id
     */
    int id;
    /**
     * 唯一标识id
     */
    String uuid;
    /**
     * 名称
     */
    String name;
    /**
     * 是否可见，默认可见
     */
    bool bVisible;
    /**
     * 是否每帧调用 render, 默认 false
     */
    bool bTickable;
    /**
     * 位置
     */
    Vector3 location;
    /**
     * 上方向
     */
    Vector3 up;
    /**
     * 旋转
     */
    Vector3 rotation;

    /**
     * 缩放
     */
    Vector3 scale;

public:
    //事件
    void onInit() override;
    void onRender(float elapsedTime, Matrix4x4 proj, Matrix4x4 view, Matrix4x4 pworld) override;
    void getUI() override;
public:
    Object3D();
    ~Object3D();

    /**
     * 应用矩阵
     * @param matrix 矩阵
     */
    void applyMatrix(Matrix4x4 matrix);

    /**
     * 应用材质
     * @param p_material 材质实例
     */
    void applyMaterial(Material *p_material);

    /**
     * 返回模型矩阵
     * @return 矩阵
     */
    Matrix4x4 getModelmatrix();
};


#endif //MRENDER_OBJECT3D_H
